﻿//------------------------------------------------------------------------------ 
// <copyright file="JBanner.cs" company="Fm Computer">
//     Copyright (c) Fm Computer di Menatti Fulvia.  All rights reserved.
// </copyright>
//----------------------------------------------------------------------------- 
namespace FmjQuery
{
    using System.ComponentModel;
    using System.Text;
    using System.Web.UI;

    /// <summary>
    /// JBanner Animation
    /// </summary>
    [ToolboxData("<{0}:JBanner runat=server Speed=normal AnimationType=fade ChangeType=sequence />")]
    [DefaultProperty("TargetControlID")]
    [NonVisualControl]
    public class JBanner : JQueryExtendControl
    {
        #region Costruct
        /// <summary>
        /// Initializes a new instance of the JBanner class.
        /// </summary>
        public JBanner()
        {
            this.IsRenderControl = false;
        }
        #endregion

        #region Property
        /// <summary>
        /// Gets or sets Animation Type
        /// </summary>
        [Description("Animation Type")]
        [DefaultValue("fade")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public InnerFadeAnimationType AnimationType
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets Animation Change Type
        /// </summary>
        [Description("Animation Type for Change news")]
        [DefaultValue("sequence")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public InnerFadeAnimationChangeType ChangeType
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets animation speed
        /// </summary>
        [Description("Animation Speed")]
        [DefaultValue("normal")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public SpeedType Speed
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets for for change image
        /// </summary>
        [Description("Millisecond beetween change image")]
        public int TimeOut
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets height of container
        /// </summary>
        [Description("Container Height")]
        public string ContainerHeight
        {
            get;
            set;
        }
        #endregion

        #region JQueryExtendControl
        /// <summary>
        /// Return list of webresource
        /// </summary>
        /// <returns>web resources</returns>
        public override JWebSources GetResources()
        {
            return null;
        }

        /// <summary>
        /// Gets list of css image resources
        /// </summary>
        /// <returns>list of images</returns>
        public override CssResources GetCssResources()
        {
            return null;
        }

        /// <summary>
        /// Gets list of client nameSpace
        /// </summary>
        /// <returns>list of namespace</returns>
        public override ClientNameSpaces GetClientNameSpace()
        {
            return null;
        }

        /// <summary>
        /// Create jQuery control
        /// </summary>
        public override void CreateJControl()
        {
            this.Manager.InnerFade = true;

            if (this.Enabled)
            {
                // create script
                StringBuilder builder = new StringBuilder(string.Empty);

                builder.AppendFormat("$('#{0}').innerfade(", this.TargetControlClientID);
                builder.Append("{");

                if (this.TimeOut > 0)
                {
                    builder.AppendFormat("timeout: {0},", this.TimeOut);
                }

                if (!string.IsNullOrEmpty(this.ContainerHeight))
                {
                    builder.AppendFormat("containerheight: '{0}',", this.ContainerHeight);
                }

                if (!string.IsNullOrEmpty(this.CssClass))
                {
                    builder.AppendFormat("runningclass: '{0}',", this.CssClass);
                }

                builder.AppendFormat("speed: '{0}',", this.Speed);
                builder.AppendFormat("type: '{0}',", this.AnimationType);
                builder.AppendFormat("animationtype: '{0}'", this.ChangeType);
                builder.Append("});");

                Utility.RegisterStartUpScript(Page, string.Concat("banner_", this.ClientID), builder.ToString());
            }
        }
        #endregion
    }
}
